//
//  UIApplication+Extension.swift
//  Lease_IOS
//
//  Created by Mr.wang on 2018/12/20.
//  Copyright © 2018 Mr.wang. All rights reserved.
//

import UIKit

extension UIApplication {
    
    var currentViewController: UIViewController {
        let rootVC = (keyWindow?.rootViewController)!
        if let presentedVC = rootVC.presentedViewController {
            return presentedVC
        }
        return rootVC
    }
    
    var bottomSafeDistance: CGFloat {
        if #available(iOS 11.0, *) {
            return keyWindow?.safeAreaInsets.bottom ?? 0
        } else {
            return 0
        }
    }
    
    var topSafeDistance: CGFloat {
        if #available(iOS 11.0, *) {
            return keyWindow?.safeAreaInsets.top ?? 0
        } else {
            return 0
        }
    }
    
    var statusBarHeight: CGFloat {
        let height = statusBarFrame.height
        if height > 40 {
            return height
        } else {
            return 20
        }
    }
}
